home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / RxMUI / Examples / SendMsg.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2004-01-31  |  12.1 KB  |  399 lines

  1. /*
  2. ** Name: SendMsg.rexx
  3. ** Version: 2.1
  4. ** Date: 16.3.2001
  5. ** Author: Alfonso Ranier
  6. ** Description: Sends email/new messages
  7. */
  8.  
  9. signal on halt
  10. signal on break_c
  11.  
  12. call Init()
  13. call CreateApp()
  14. call HandleApp()
  15. /* never reached */
  16. /***********************************************************************/
  17. Init: procedure expose global.
  18.     l="rmh.library";if ~show("L",l) then;if ~addLib(l,-5,-30) then exit
  19.     if addLibrary("rxmui.library","rexxsupport.library","rxsocket.library")~=0 then exit
  20.  
  21.     call SetRxMUIStack(64000) /* CManager uses NList ! */
  22.     
  23.     call MacroEnv("global","ProgDir CD")
  24.     global.ver=2.4
  25.     global.date="(5.3.2003)"
  26.     global.descr="Sends emails/news messages"
  27.     global.Author="Alfonso Ranieri"
  28.  
  29.     call RxMUIOpt("DebugMode ShowErr")
  30.  
  31.     global.MacroNotify=global.NoExtName"_"time(s)
  32.     global.mns=MacroNotifyCreate(global.MacroNotify)
  33.     if global.mns=0 then exit
  34.  
  35.     parm.0.flag=0
  36.     parm.1.value=""
  37.     parm.2.value=""
  38.     parm.3.value=""
  39.  
  40.     if ~global.WB? then
  41.         if ~RMHReadArgs("NEW/S,TO/K,SUBJECT/K,MSG/K/F") then do
  42.             call PrintFault()
  43.             exit
  44.         end
  45.  
  46.     global.MsgType=parm.0.flag
  47.     global.to=parm.1.value
  48.     global.esubject=parm.2.value
  49.     global.nsubject=parm.2.value
  50.     global.msg=parm.3.value
  51.  
  52.     global.CM?=exists("MUI:Libs/MUI/CManager.mcc")
  53.     global.App?=0
  54.  
  55.     return
  56. /***********************************************************************/
  57. CreateApp: procedure expose global.
  58.  
  59.     strip.0="MProject"
  60.      MProject.Class="menu"
  61.      MProject.Title="Project"
  62.       MProject.0=MenuItem("MAbout","?\About...","?")
  63.       MProject.1=MenuItem("MAboutRxMUI","X\About RxMUI...")
  64.       MProject.2=MenuItem("MAboutMUI","!\About MUI...")
  65.       MProject.3=MenuItem("","BAR")
  66.       MProject.4=MenuItem("MHide","H\Hide")
  67.       MProject.5=MenuItem("","BAR")
  68.       MProject.6=MenuItem("MQuit","Q\Quit")
  69.     strip.1="MEditor"
  70.      MEditor.Title="Editor"
  71.       MEditor.Class="menu"
  72.       MEditor.0=MenuItem("MMUI","M\MUI Settings...")
  73.     if NewObj("Menustrip","strip")>0 then call ShowErr(0)
  74.  
  75.     to.CycleChain=1
  76.     if string("to","t")="" then call ShowErr(0)
  77.  
  78.     if global.CM? then do
  79.         ToObj.object="cmg"
  80.          cmg.Class="group"
  81.          cmg.Frame="InputList"
  82.           cmg.0="cm"
  83.            cm.Class="cm"
  84.            cm.AutoLoad=1
  85.            cm.HideUsers=0
  86.            cm.HideWWW=1
  87.            cm.HideFtp=1
  88.            cm.HideChat=1
  89.            cm.HideTelnet=1
  90.            cm.NoMenu=1
  91.            cm.DoubleClick="GLOBAL.CMENTRY"
  92.         ToObj.String="to"
  93.          tpb.CycleChain=1;
  94.         ToObj.Button=MakeObj("tpb","ImageButton","Popup")
  95.         ToObj.Toggle=1
  96.  
  97.         if NewObj("popobject","ToObj")>0 then call ShowErr(0)
  98.     end
  99.     else ToObj="to"
  100.  
  101.     app.Title=global.NoExtName
  102.     app.Version="$VER:" global.NoExtName global.ver global.date
  103.     app.Copyright="Copyright 2001-2003 by" global.author
  104.     app.Author=global.author
  105.     app.Description=global.descr
  106.     app.Base=upper(global.NoExtName)
  107.     app.MenuStrip="strip"
  108.     app.DiskObject=global.NoExtName
  109.     app.SubWindow="mwin"
  110.  
  111.      mwin.ID="MAIN"
  112.      mwin.Title=global.NoExtName
  113.      mwin.Contents="mgroup"
  114.  
  115.       call child("mgroup","mg","group")
  116.  
  117.        call child("mg","swg","group")
  118.         swg.Horiz=1
  119.         swg.0=label("Send _what")
  120.          MsgType.CycleChain=1
  121.         swg.1=MakeObj("MsgType","Cycle","EMail|New","w",global.MsgType)
  122.         swg.2=hspace(8)
  123.         swg.3=label("Show setti_ngs")
  124.          se.ObjectID="SHOW"
  125.          se.CycleChain=1
  126.         swg.4=checkmark("se",1,"n")
  127.  
  128.        call child("mg","eg","group")
  129.         eg.Frame="group"
  130.         eg.FrameTitle="Message"
  131.         eg.Background="groupback"
  132.          call child("eg","sg","group")
  133.           sg.PageMode=1
  134.           sg.ActivePage=global.MsgType
  135.            call child("sg","sge","group")
  136.             sge.Columns=2
  137.              call child("sge",label("_To"))
  138.              call child("sge",ToObj)
  139.              call child("sge",label("S_ubject"))
  140.              esubject.CycleChain=1; call child("sge",string("ESUBJECT","u",global.esubject))
  141.            call child("sg","sgn","group")
  142.             sgn.Columns=2
  143.              call child("sgn",label("_Group"))
  144.              group.CycleChain=1; call child("sgn",string("group","g"))
  145.              call child("sgn",label("S_ubject"))
  146.              nsubject.CycleChain=1; call child("sgn",string("NSUBJECT","u",global.nsubject))
  147.           textg.Spacing=0
  148.          call child("eg","textg","HGroup")
  149.           call child("textg","text","TextEditor")
  150.           text.Slider="scroller"
  151.           text.Export="EMAIL"
  152.           text.Contents=global.msg
  153.           call child("textg","scroller","Scrollbar")
  154.  
  155.       call child("mg","g0","group")
  156.        g0.Weight=0
  157.        g0.Frame="group"
  158.        g0.FrameTitle="Settings"
  159.        g0.BAckground="groupback"
  160.        g0.Columns=2
  161.         call child("g0",label("Re_al name"))
  162.         name.CycleChain=1; name.ObjectID="NAME"; call child("g0",string("NAME","a"))
  163.         call child("g0",label("_EMail"))
  164.         email.CycleChain=1; email.ObjectID="EMAL"; call child("g0",string("EMAIL","e"))
  165.         call child("g0",label("_Host"))
  166.         call child("g0","hg","group")
  167.          hg.PageMode=1
  168.          hg.ActivePage=global.MsgType
  169.           ehost.CycleChain=1; ehost.ObjectID="MHOS"; call child("hg",string("EHOST","h"))
  170.           nhost.CycleChain=1; nhost.ObjectID="NHOS"; call child("hg",string("NHOST","h"))
  171.  
  172.        info.Weight=20;
  173.       call child("mgroup",text("info","Welcome to SendMsg!"))
  174.  
  175.       call child("mgroup","abg","group")
  176.        abg.Weight=20
  177.        abg.Horiz=1
  178.        abg.PageMode=1
  179.         call child("abg","abg0","group")
  180.         abg0.Horiz=1
  181.            send.CycleChain=1;
  182.           call child("abg0",button("SEND","_Send"))
  183.           call child("abg0",hspace())
  184.            quit.CycleChain=1;
  185.           call child("abg0",button("QUIT","_Quit"))
  186.            stop.CycleChain=1;
  187.         call child("abg",button("STOP","_Stop"))
  188.  
  189.     if NewObj("application","app")>0 then call ShowErr(0)
  190.  
  191.     call notify("mwin","CloseRequest",1,"app","return","call SafeQuit(1)")
  192.  
  193.     call notify("MAbout","MenuTrigger","everytime","app","about","mwin")
  194.     call notify("MAboutRxMUI","MenuTrigger","everytime","app","aboutrxmui","mwin")
  195.     call notify("MAboutMUI","MenuTrigger","everytime","app","aboutmui","mwin")
  196.     call notify("MHide","MenuTrigger","everytime","app","Set","iconified",1)
  197.     call notify("MQuit","MenuTrigger","everytime","app","return","call SafeQuit(1)")
  198.     call notify("mmui","MenuTrigger","everytime","app","openconfigwindow","win")
  199.  
  200.     call notify("MsgType","active","everytime","hg","Set","ActivePage","triggervalue")
  201.     call notify("MsgType","active","everytime","sg","Set","ActivePage","triggervalue")
  202.     call notify("se","Selected","everytime","g0","Set","ShowMe","triggervalue")
  203.  
  204.     call notify("send","pressed",0,"app","return","call SafeStart()")
  205.     call notify("stop","pressed",0,"app","return","call SafeQuit(0)")
  206.     call notify("quit","pressed",0,"app","return","call SafeQuit(1)")
  207.  
  208.     call notify("abg","ActivePage","everytime","mg","Set","disabled","triggervalue")
  209.  
  210.     if global.CM? then do
  211.         call Notify("cm","doubleclick","everytime","ToObj","close",1)
  212.         call Notify("ToObj","success",1,"app","return","call set('to','contents',global.cmentry.email)")
  213.     end
  214.  
  215.     call set("g0","showme",xget("se","selected"))
  216.     call set("mwin","defaultobject","send")
  217.  
  218.     if global.MsgType then call set("group","contents",global.to)
  219.     else call set("to","contents",global.to)
  220.  
  221.     call DoMethod("app","load","env")
  222.  
  223.     call set("mwin","open",1)
  224.  
  225.     global.App?=1
  226.     return
  227. /**************************************************************************/
  228. HandleApp: procedure expose global.
  229.  
  230.     ctrl_c=2**12
  231.     mask=or(global.mns,ctrl_c)
  232.  
  233.     do forever
  234.         if NewHandle("app","h",mask)>0 then call ShowErr(2)
  235.  
  236.         if and(h.signals,ctrl_c)>0 then call SafeQuit(1)
  237.         if and(h.signals,global.mns)>0 then call HandleMacroEvent()
  238.  
  239.         if h.EventFlag then
  240.             select
  241.                 when h.event="QUIT" then call SafeQuit(1)
  242.                 otherwise interpret h.event
  243.             end
  244.  
  245.     end
  246.     /* never reached */
  247. /***********************************************************************/
  248. HandleMacroEvent: procedure expose global.
  249.     do forever
  250.         ev=MacroNotifyGetEvent(global.MacroNotify)
  251.         if ev="" then return
  252.  
  253.         parse var ev ev child d
  254.         select
  255.  
  256.             when ev="STARTED" then do
  257.                 call set("abg","ActivePage",1)
  258.                 call set("app","sleep",0)
  259.             end
  260.  
  261.             when ev="ENDED" then do
  262.                 call set("abg","ActivePage",0)
  263.             end
  264.  
  265.             when ev="INFO" then do
  266.                 call info(d)
  267.             end
  268.  
  269.             otherwise nop
  270.         end
  271.     end
  272.     /* never reached */
  273. /***********************************************************************/
  274. SafeStart: procedure expose global.
  275.  
  276.     call set("app","sleep",1)
  277.  
  278.     if ~IsLibOn("SOCKET") then do
  279.         call info("No TCP/IP stack running!")
  280.         call set("app","sleep",0)
  281.         return
  282.     end
  283.  
  284.     if ~exists("sendmsgfun.rexx") then do
  285.         call info "Macro 'sendmsgfun.rexx' not found!!!"
  286.         call set("app","sleep",0)
  287.         return
  288.     end
  289.  
  290.     var.News=xget("MsgType","active")
  291.     if var.News then do
  292.         var.News=1
  293.         var.Host=xget("nhost","contents")
  294.         var.Name=xget("name","contents")
  295.         var.Email=xget("email","contents")
  296.         var.To=xget("group","contents")
  297.         var.Subject=xget("nsubject","contents")
  298.         var.Text=xget("text","contents")
  299.     end
  300.     else do
  301.         var.Host=xget("ehost","contents")
  302.         var.Name=xget("name","contents")
  303.         var.Email=xget("email","contents")
  304.         var.To=xget("to","contents")
  305.         var.Subject=xget("esubject","contents")
  306.         var.Text=xget("text","contents")
  307.     end
  308.  
  309.     if var.Host="" then do
  310.         call info("No host supplied.")
  311.         call set("app","sleep",0)
  312.         return
  313.     end
  314.  
  315.     if pos(":",var.Host)>0 then do
  316.         parse var var.Host var.Host ":" var.HostPort
  317.         if var.HostPort<0 | var.HostPort>65535 then do
  318.             call info("Invalid port" var.HostPort".")
  319.             call set("app","sleep",0)
  320.             return
  321.         end
  322.     end
  323.     else
  324.         if var.News then var.HostPort=119
  325.         else var.HostPort=25
  326.  
  327.     if var.Name="" then do
  328.         call info("No Real name supplied.")
  329.         call set("app","sleep",0)
  330.         return
  331.     end
  332.  
  333.     if var.Email="" then do
  334.         call info("No EMail address supplied.")
  335.         call set("app","sleep",0)
  336.         return
  337.     end
  338.  
  339.     if var.To="" then do
  340.         if var.News then call info("No newsgroup supplied.")
  341.         else call info("No destination supplied.")
  342.         call set("app","sleep",0)
  343.         return
  344.     end
  345.  
  346.     if var.Subject="" then do
  347.         call info("No subject supplied.")
  348.         call set("app","sleep",0)
  349.         return
  350.     end
  351.  
  352.     if var.Text="" then do
  353.         call info("No message text supplied.")
  354.         call set("app","sleep",0)
  355.         return
  356.     end
  357.  
  358.     call info("Launching child...")
  359.  
  360.     var.MacroNotify=global.MacroNotify
  361.     call StemToVar("var")
  362.     call RxsCall("SendMsgFun.rexx")
  363.  
  364.     return
  365. /**************************************************************************/
  366. SafeQuit: procedure expose global.
  367. parse arg e
  368.     if e then do
  369.         if global.App? then do
  370.             call set("mwin","open",0)
  371.             call DoMethod("app","save","env")
  372.             call DoMethod("app","save","envarc")
  373.         end
  374.         exit
  375.     end
  376.     call MacroNotifySync()
  377.     return
  378. /***************************************************************************/
  379. info: procedure expose global.
  380. parse arg txt
  381.     call set("info","contents",txt)
  382.     return
  383. /**************************************************************************/
  384. halt:
  385. break_c:
  386.     call SafeQuit(1)
  387. /**************************************************************************/
  388. ShowErr: procedure expose global.
  389. parse arg err
  390.     select
  391.         when err=0 then msg="Can't create Application"
  392.         when err=1 then msg="Can't open Window"
  393.         otherwise msg="Too few memory"
  394.     end
  395.     call EasyRequest(msg,global.NoExtName)
  396.     call SafeQuit(1)
  397. /**************************************************************************/
  398.  
  399.